<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/myapp.css">
	</head>

	<body>
		<!--标题栏开始-->
		<header id="header" class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">群聊</h1>
		</header>
		<ul id="groupListID" class="mui-table-view mui-table-view-chevron" style="margin-top: 44px;">
		</ul>
		<!--新加好友、群组结束-->
		<script src="../js/mui.min.js"></script>
		<script src="../js/jquery-1.9.1.js"></script>
		<script src="../js/websqlwrapper.js"></script>
		<script src="../js/constant.js"></script>
		<script>
			var dataBase = openDatabase("hcrchatDB", "1", "database for local caching", 20 * 1042 * 1024, function() {});
			function updateGroupList() {
				dataBase.transaction(function(fx) {
					//查询数据
					fx.executeSql(
						"select group_id,group_name from tab_group where group_id in(select group_id from tab_group_member where user_id=?)", [oneself],
						function(fx, result) {
							var ul = document.getElementById("groupListID");
							if(result.rows.length > 0) {
								console.log("zongshu"+result.rows.length);
								ul.innerHTML='';
								for(var index = 0; index < result.rows.length; index++) {
									console.log("smzhi" + result.rows.item(index)["group_id"] + "kan" + result.rows.item(index)["group_name"]);
									var li = document.createElement("li");
									var str = "";
									var em = result.rows.item(index)["group_id"];
									var emu = result.rows.item(index)["group_name"];
									str += "<li id=" + result.rows.item(index)["group_id"] + "," + result.rows.item(index)["group_name"] + " class='mui-table-view-cell'><img class='mui-media-object mui-pull-left' src='../images/group-head.jpg'><div 											class='mui-media-body'>";
									str += "<div class='mui-ellipsis center-name'><a>" + result.rows.item(index)["group_name"] + "</a></div>";
									str += "</div>";
									li.innerHTML = str;
									ul.appendChild(li);
								}
								mui('.mui-table-view-chevron').on('tap', 'li', function() {
									var em = this.getAttribute("id");
									var array;
									if(em != null) {
										array = em.split(",");
										mui.openWindow({
											id: oneself + "" + array[0],
											url: '/examples/im-chat-group.html',
											extras: {
												title: array[1],//需要传值群名称
												userid: array[0]//需要传值群id
											},
											createNew:true
										});
									}

								})
							}

						}
					)

				});
			}
			updateGroupList();
		</script>